//
//  NSString+HXSHA_1.m
//  UI24-加密（MD5）
//  Created by 韩旭 on 16/8/16.
//  Copyright © 2016年 lanou. All rights reserved.
#import "NSString+HXSHA_1.h"
#import <CommonCrypto/CommonCrypto.h>
@implementation NSString (HXSHA_1)
- (NSString *)stringWithSHA_1 {
//    1 将字符串占城C语言字符串
    const char *cStirng = [self UTF8String];
//    2. 求长度
    CC_LONG len = (CC_LONG)strlen(cStirng);
    unsigned char bytes[CC_SHA1_DIGEST_LENGTH];
    CC_SHA1(cStirng, len, bytes);
    
    NSMutableString *finalSha1 = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH];
    for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) {
        [finalSha1 appendFormat:@"%02x", bytes[i]];
    }
    return finalSha1;
}
@end